<?php
	class Admin_Log extends MY_Controller {
		function Admin_Log() {
			parent::__construct();
			@session_start();
			$this->mod_ad->is_logged_in();		
			$_SESSION['redirect'] = $this->uri->uri_string();
			$this->check_permission();	
			//kiem tra quyen truy cap 
			$this->check_permission();
		}
		
		function index(){
			$data['vl_sort'] = "DESC";	
			$data['title'] = "Quản lý nhật ký log - admin";
			$data['table'] = 'admin_log';
			$data['controller'] = 'admin_log';
			$data['content_admin'] = 'back_end/admin_log/index';
			
			$this->db->order_by('parent_id','asc');
			//lay ra cac danh muc cap 1
			$data['category_admin_1'] = $this->db->get_where('admin_menu',array('level' => 1))->result_array();
			//lay ra cac danh muc cap 2
			$data['category_admin_2'] = $this->db->get('admin_menu',array('level' => 2))->result_array();
			//lay ra category hien tai	
			$uri_value = $this->uri->segment(2);
			$this->db->select('root_path,id');
			$data['category_admin_active'] = $this->db->get_where('admin_menu',array('controller' => $uri_value))->row_array();
			
			$data['sort'] = 'ASC';
			$this->db->order_by('parent_id','asc');
			$data['category_admin'] = $this->db->get('admin_menu')->result_array();
			
			$per_page = 20;
			$uri = 4;
			$data['admin_log_value'] = $this->mod_lib->load_all('admin_log','',array(),$per_page,$this->uri->segment($uri),array("id"=>"desc"));																													
			$config['base_url']     =  site_url('back_end/admin_log/index/');
			$config['total_rows']   =  $this->db->count_all('admin_log');
			$config['per_page']     =  $per_page; 
			$config['uri_segment']  =  $uri; 
			$this->pagination->initialize($config);
			$this->load->view('back_end/template_backend',$data);	
		}
		
		function sort($field,$sort = '') {
			$per_page = 10;
			$uri = 4;
			$data['title'] = "Admin Menu - Sort";
			$data['table'] = 'admin_menu';
			$data['controller'] = 'admin_menu';
			$data['content_admin'] = 'back_end/admin_log/index';
			
			//lay ra cac danh muc cap 1
			$data['category_admin_1'] = $this->db->get_where('admin_menu',array('level' => 1))->result_array();
			//lay ra cac danh muc cap 2
			$data['category_admin_2'] = $this->db->get('admin_menu',array('level' => 2))->result_array();
			//lay ra category hien tai
			$uri_value = $this->uri->segment(2);
			$this->db->select('root_path,id');
			$data['category_admin_active'] = $this->db->get_where('admin_menu',array('controller' => $uri_value))->row_array();
			
			$uri_value_4 =  $this->uri->segment(4);
			$uri_value_5 =  $this->uri->segment(5);
			
			$_SESSION['order_sort'] = array(
				$uri_value_4 => $uri_value_5 
			);
			
			$_SESSION['sort'] = $sort;
			$_SESSION['field'] = $field;
			
			if ($sort == 'DESC') {
				$data['sort'] =  'ASC';
			} else if($sort == 'ASC') {
				$data['sort'] =  'DESC';
			}
			
			$data_search = $this->mod_lib->search('admin_log','',array(),array(),array("id"=>"desc"));
			$data['admin_log_value'] = $this->mod_lib->load_search('admin_log','',array(),array(),$per_page,$this->uri->segment($uri),array($_SESSION['field']=>$_SESSION['sort']));		
			$config['base_url']     =  site_url('back_end/admin_log/index');

			$config['total_rows']   =  count($data_search);
			$config['per_page']     =  $per_page;
			$config['uri_segment']  =  $uri; 
			$this->pagination->initialize($config);		
			$this->load->view('back_end/template_backend',$data);
		}
		
		function delete() {
			$ids =  implode(",", $this->input->post('value_id'));

			if(!empty($ids)){
				if($this->mod_lib->deleteRecord('admin_log',$ids)){
					$this->session->set_flashdata('msview', 'Xóa thành công !');
				} else {
					$this->session->set_flashdata('msview', 'Xóa thất bại !');
				}
				
				$this->session->set_flashdata('msview', 'Xóa thành công !');
			} else {
				$this->session->set_flashdata('msview', 'Xóa thất bại !');
			}		
			redirect('back_end/admin_log');
		}

		function deleteId($id) {
			if(!empty($id)){
				if($this->mod_lib->deleteRecord('admin_log',$id)){
					$this->session->set_flashdata('msview', 'Xóa thành công !');
				} else {
					$this->session->set_flashdata('msview', 'Xóa thất bại !');
				}
				
				$this->session->set_flashdata('msview', 'Xóa thành công !');
			} else {
				$this->session->set_flashdata('msview', 'Xóa thất bại !');
			}		
			redirect('back_end/admin_log');
		}
		
		
	}
?>